using System.Windows.Input;

namespace GameSaveManager;

public class AppSettings
{
    public Key BackupHotkeyKey { get; set; } = Key.F5;
    public ModifierKeys BackupHotkeyModifiers { get; set; } = ModifierKeys.None;
    public Key RestoreHotkeyKey { get; set; } = Key.F6;
    public ModifierKeys RestoreHotkeyModifiers { get; set; } = ModifierKeys.None;
}

public static class SettingsManager
{
    private const string SettingsFilePath = "settings.json";

    public static AppSettings Load()
    {
        if (System.IO.File.Exists(SettingsFilePath))
        {
            try
            {
                string json = System.IO.File.ReadAllText(SettingsFilePath);
                if (!string.IsNullOrWhiteSpace(json))
                {
                    var settings = Newtonsoft.Json.JsonConvert.DeserializeObject<AppSettings>(json);
                    if (settings != null)
                    {
                        return settings;
                    }
                }
            }
            catch
            {
                // If loading fails, return default settings
            }
        }

        // Return default settings
        return new AppSettings();
    }

    public static void Save(AppSettings settings)
    {
        try
        {
            string json = Newtonsoft.Json.JsonConvert.SerializeObject(settings, Newtonsoft.Json.Formatting.Indented);
            System.IO.File.WriteAllText(SettingsFilePath, json);
        }
        catch (Exception ex)
        {
            throw new Exception($"Failed to save settings: {ex.Message}");
        }
    }
}
